package com.ge.modules.sys.controller;

import com.ge.common.utils.PageUtils;
import com.ge.common.utils.Query;
import com.ge.common.utils.R;
import com.ge.modules.entity.TbHeadImgEntity;
import com.ge.modules.sys.service.SysTbHeadImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys/headimg")
public class SysTbHeadimgController {

    @Autowired
    private SysTbHeadImgService headImgService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:headimg:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<TbHeadImgEntity> headImgList = headImgService.queryList(query);
        int total = headImgService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(headImgList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:headimg:info")
    public R info(@PathVariable("id") Integer id){
        TbHeadImgEntity headImg = headImgService.queryObject(id);

        return R.ok().put("headImg", headImg);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:headimg:save")
    public R save(@RequestBody TbHeadImgEntity headImg){
        headImgService.save(headImg);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:headimg:update")
    public R update(@RequestBody TbHeadImgEntity headImg){
        headImgService.update(headImg);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:headimg:delete")
    public R delete(@RequestBody Integer[] ids){
        headImgService.deleteBatch(ids);

        return R.ok();
    }

}
